<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
	<th:block th:include="include :: header('新增合作伙伴')" />
	<th:block th:include="include :: jasny-bootstrap-css" />
</head>
<body class="white-bg">
	<div class="wrapper wrapper-content animated fadeInRight ibox-content">
		<form class="form-horizontal m" id="form-partner-add">
			<div class="form-group">
				<label class="col-sm-3 control-label">合作伙伴名称：</label>
				<div class="col-sm-8">
					<input class="form-control" type="text" name="partnerName" id="partnerName" required>
				</div>
			</div>

			<div class="form-group">
				<label class="col-sm-3 control-label ">logo：</label>
				<div class="col-sm-8">
					<input id="filePath" name="filePath" class="form-control" type="file">
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label">网站地址：</label>
				<div class="col-sm-8">
					<input class="form-control" type="text" name="partnerNet" id="partnerNet" required>
				</div>
			</div>
		</form>
	</div>
	<th:block th:include="include :: footer" />
	<script type="text/javascript">
		var prefix = ctx + "user/partner";

		$("#form-post-add").validate({
			onkeyup: false,
			rules:{
				partnerNet:{
					remote: {
		                url: prefix +"/checkNet",
		                type: "post",
		                dataType: "json",
		                data: {
		                	"partnerNet" : function() {
		                        return $.common.trim($("#partnerNet").val());
		                    }
		                },
		                dataFilter: function(data, type) {
		                	return $.validate.unique(data);
		                }
		            }
				},

				postSort:{
					digits:true
				},
			},
			messages: {
		        "partnerNet": {
		            remote: "网址已经存在"
		        }
		    },
		    focusCleanup: true
		});
		/*function submitHandler() {
	        if ($.validate.form()) {
	        	$.operate.save(prefix + "/add", $('#form-partner-add').serialize());
	        }
	    }*/


	    //文件上传下载
		function submitHandler() {
			if ($.validate.form()) {
				uploadFile();
			}
		}
		function uploadFile() {
			var formData = new FormData();
			if ($('#filePath')[0].files[0] == null) {
				$.modal.alertWarning("请先选择文件路径");
				return false;
			}
			formData.append('fileName', $("#fileName").val());
			formData.append('file', $('#filePath')[0].files[0]);
			formData.append('partnerName',$('#partnerName').val());
			formData.append('partnerNet',$('#partnerNet').val());
			$.ajax({
				url: prefix + "/add",
				type: 'post',
				cache: false,
				data: formData,
				processData: false,
				contentType: false,
				dataType: "json",
				success: function(result) {
					$.operate.successCallback(result);
				}
			});
		}

	</script>
</body>
</html>
